/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 22652
 * Date: 2024-05-21
 * Time: 16:32
 */
public class rob {
    public static int rob(int[] nums) {
        return Math.max(nums[0]+startrob(nums, 2, nums.length - 2),
                startrob(nums, 1, nums.length - 1));
    }

    private static int startrob(int[] nums, int left, int right) {
        if(left > right) return 0;
        // 1. 创建 dp 表
        // 2. 初始化
        // 3. 填表
        // 4. 返回
        int n = nums.length;
        int[] f = new int[n];
        int[] g = new int[n];
        f[left] = nums[left];
        for (int i = left + 1; i <= right; i++)
        {
            f[i] = g[i - 1] + nums[i];
            g[i] = Math.max(g[i - 1], f[i - 1]);
        }
        return Math.max(f[right], g[right]);
    }
    public static void main(String[] args) {
        int[] nums={1};
        System.out.println(rob(nums));
    }
}
